package com.egene.tw.activity.member;

import android.text.Html;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.egene.tw.R;
import com.egene.tw.base.RecycleBaseAdapter;
import com.egene.tw.model.UserCenterItem;
import com.egene.tw.utils.ImageUtil;

public class KnowRecycleAdapter extends RecycleBaseAdapter {


    public KnowRecycleAdapter() {
    }

    public KnowRecycleAdapter(View headerView) {
        mHeaderView = headerView;
    }

    @Override
    public View onCreateItemView(ViewGroup parent, int viewType) {
        return getLayoutInflater(parent.getContext()).inflate(R.layout.item_know, null);
    }

    @Override
    protected RecycleBaseAdapter.ViewHolder onCreateItemViewHolder(View view, int viewType) {
        return new ViewHolder(viewType, view);
    }

    @Override
    protected void onBindItemViewHolder(RecycleBaseAdapter.ViewHolder vh, int position) {
        super.onBindItemViewHolder(vh, position);
        KnowRecycleAdapter.ViewHolder holder = (KnowRecycleAdapter.ViewHolder) vh;
        UserCenterItem userCenterItem = (UserCenterItem) _data.get(position);

        if(userCenterItem.ischecked()){
            holder.viewContainer.setBackgroundResource(R.drawable.style_item);
        }else{
            holder.viewContainer.setBackgroundResource(R.drawable.style_item_disable);
        }

        switch (userCenterItem.getRiskvalue().intValue()){
            case UserCenterItem.RISK_SMALL:
                holder.tvRisk.setTextColor(holder.tvRisk.getContext().getResources().getColor(R.color.risk_small));
                break;
            case UserCenterItem.RISK_MEDIUM:
                holder.tvRisk.setTextColor(holder.tvRisk.getContext().getResources().getColor(R.color.risk_medium));
                break;
            case UserCenterItem.RISK_HIGH:
                holder.tvRisk.setTextColor(holder.tvRisk.getContext().getResources().getColor(R.color.risk_high));
                break;
        }
        holder.tvRisk.setText(userCenterItem.getRiskname());
        String img = userCenterItem.getSmallimg();
        if(TextUtils.isEmpty(img)){
            img = "123";
        }

        ImageUtil.loadImage(holder.ivHead.getContext(), holder.ivHead, img);
        holder.tvTitle.setText(userCenterItem.getName());
        holder.tvContent.setText(userCenterItem.getRiskremark());
//        holder.tvContent.setText(Html.fromHtml(userCenterItem.getCategorydesc()));
    }

    public static class ViewHolder extends RecycleBaseAdapter.ViewHolder {
        public View viewContainer;
        public ImageView ivHead;
        public TextView tvTitle;
        public TextView tvContent;
        public TextView tvRisk;

        public ViewHolder(int viewType, View view) {
            super(viewType, view);
            viewContainer = view.findViewById(R.id.viewContainer);
            tvTitle = (TextView) view.findViewById(R.id.tvTitle);
            tvContent = (TextView) view.findViewById(R.id.tvContent);
            tvRisk = (TextView) view.findViewById(R.id.tvRisk);
            ivHead = (ImageView) view.findViewById(R.id.ivHead);
        }
    }
}
